package com.example.springbootdemo.controller;

import com.example.springbootdemo.bean.entity.User;
import com.example.springbootdemo.util.OkHttpUtils;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author hh
 * @date 2022/2/28
 */
@Api(tags = "OkHttp服务")
@RestController
@RequestMapping("test")
public class OkHttpController {

    @GetMapping("get")
    public String get(){
        String url = "http://localhost:8088/api/user";
        // String url = "http://localhost:8088/test/hi";
        Map<String, String> headers = new HashMap<>(16);
        headers.put("Authorization", "Bearer eyJhbGciOiJIUzUxMiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAAAKtWKi5NUrJSerqh_-meXUo6SqkVBUpWhmYmZgamxmbmxjpKmYklUAETMxNz41oAOp3AnjIAAAA.ole3Pa1cmVdPz0RePWbUYK6UBRRnRg5tAHpbON7UlMlXsIk0wOqD1WcczDAIoM0iCtSXcI7iz-mjrCcO3NaeZA");

        HashMap<String, String> param = new HashMap<>(16);
        param.put("userName", "小huihui");
        param.put("tel", "15225623166");
        param.put("password", "123456");
        param.put("gender", "1");
        param.put("email", "123@163.com");
        param.put("age", "50");

        return OkHttpUtils.builder()
                .url(url)
                .headers(headers)
                .param(param)
                .post(true)
                .sync();
    }

    @GetMapping("hi")
    public User test(){
        User user = new User();
        user.setName("小明");
        user.setPassword("12345");
        user.setTel("15266666666");
        user.setEmail("123@qq.com");
        user.setGender(1);
        return user;
    }

}
